package ejemploJBullet;
/**
 *
 * @author Marlon Nunez. Junio de 2009
 */
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.*;
import com.bulletphysics.collision.dispatch.*;
import com.bulletphysics.collision.shapes.*;
import com.bulletphysics.dynamics.*;
import com.bulletphysics.linearmath.*;
import com.sun.j3d.utils.image.TextureLoader;

class Cilindro extends  CylinderShape {   
	public TransformGroup desplazamientoFigura = new TransformGroup();  
        RigidBody cuerpoRigido;
        Cylinder figura;
         
    public Cilindro(float longX, float longY, float longZ, BranchGroup conjunto, String textura){
        super( new Vector3f(longX, longY, longZ));
        if (textura==null)     
           figura  = new Cylinder (longX, longY*2, Utilidades.Apariencia(null));
        else
           figura  = new Cylinder (longX, longY*2, Cylinder.GENERATE_TEXTURE_COORDS, Utilidades.Apariencia(textura)); 
        BranchGroup ramaCilindro = new BranchGroup();
        ramaCilindro.addChild(desplazamientoFigura); 
        desplazamientoFigura.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        desplazamientoFigura.addChild(figura);
        conjunto.addChild(ramaCilindro);
      }
      public void  configurar(float masa, float elasticidad, float posX, float posY, float posZ,  DiscreteDynamicsWorld mundoDinamico ){ 
                Transform groundTransform = new Transform();
		groundTransform.setIdentity();
		groundTransform.origin.set(new Vector3f(posX, posY, posZ));
		boolean isDynamic = (masa != 0f);
		Vector3f inerciaLocal = new Vector3f(0, 0, 0);
			if (isDynamic)   this.calculateLocalInertia(masa, inerciaLocal);  // using motionstate is recommended, it provides interpolation
		DefaultMotionState EstadoDeMovimiento = new DefaultMotionState(groundTransform);
		RigidBodyConstructionInfo InformacionCuerpoR = new RigidBodyConstructionInfo(masa, EstadoDeMovimiento, this, inerciaLocal);
                InformacionCuerpoR.restitution =elasticidad;
                cuerpoRigido = new RigidBody(InformacionCuerpoR);
                cuerpoRigido.setActivationState(cuerpoRigido.DISABLE_DEACTIVATION);
                mundoDinamico.addRigidBody(cuerpoRigido); // add the body to the dynamics world
                 //rbInfo.linearDamping = 0.2f;
                 //rbInfo.angularDamping = 0.1f;                   
                //Situar en Java3D 
                Transform3D inip = new Transform3D ();
                inip.set(new Vector3f (posX, posY, posZ));
                desplazamientoFigura.setTransform(inip);
        }
}
